﻿using System;
using System.Xml.Linq;

namespace YArchitech.Temp
{
	public class Range : IHYXmlSerial
	{
		public double Max
		{
			get
			{
				return this.m_Max;
			}
		}

		public double Min
		{
			get
			{
				return this.m_Min;
			}
		}

		public Range(double min, double max)
		{
			this.Set(min, max);
		}

		public void Set(double min, double max)
		{
			this.m_Min = min;
			this.m_Max = max;
			this.m_ControlMin = (Math.Abs(min) > 0.001);
			this.m_ControlMax = (Math.Abs(max) > 0.001);
			if (this.m_ControlMax && this.m_ControlMin && min > max)
			{
				this.m_Max = min;
				this.m_Min = max;
			}
		}

		public bool Contains(double value)
		{
			bool flag = !this.m_ControlMin || value >= this.Min;
			bool flag2 = !this.m_ControlMax || value <= this.Max;
			return flag && flag2;
		}

		public double GetMinDistance(double value)
		{
			if (this.Contains(value))
			{
				return 0.0;
			}
			double val = Math.Abs(this.m_Min - value);
			double val2 = Math.Abs(value - this.m_Max);
			return Math.Min(val, val2);
		}

		public bool IsGreaterThan(double value)
		{
			return this.m_Min > value;
		}

		public bool IsLessThan(double value)
		{
			return this.m_ControlMax && this.m_Max < value;
		}

		public void WriteXml(XElement xe)
		{
			xe.SetAttributeValue("Min", this.Min);
			xe.SetAttributeValue("Max", this.Max);
		}

		public void ReadXml(XElement xe)
		{
			double min = (double)xe.Attribute("Min");
			double max = (double)xe.Attribute("Max");
			this.Set(min, max);
		}

		private double m_Max;

		private double m_Min;

		private bool m_ControlMin = true;

		private bool m_ControlMax = true;
	}
}
